/*
 * @Author: szx
 * @Date: 2022-03-29 14:52:47
 * @LastEditTime: 2022-03-29 15:03:03
 * @Description:
 * @FilePath: \leetcode\剑指offer\66\66.js
 */
/**
 * @param {number[]} a
 * @return {number[]}
 */
var constructArr = function (a) {
    const n = a.length;
    const res = new Array(n).fill(1);
    for (let i = 0; i < n - 1; i++) {
        res[i + 1] = a[i] * res[i];
    }
    // res[1,a,ab,abc,abcd]
    console.log(res);
    const tmp = new Array(n).fill(1);
    for (let i = n - 1; i >= 1; i--) {
        tmp[i - 1] = a[i] * tmp[i];
        // tmp[bcde,cde,de,e,1]
        res[i - 1] *= tmp[i - 1];
    }
    // res[bcde,acde,abde,abce,abcd]
    return res;
};
console.log(constructArr([1, 2, 3, 4, 5]));
